<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        version="2.0"
        xmlns:fn="http://www.w3.org/2005/xpath-functions"
        >
  <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
  <xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
  <xsl:param name="DESIMAL_FORMAT">#.##0,00</xsl:param>
  <xsl:param name="DESIMAL_SEPARATOR">euro</xsl:param>

  <xsl:template match="/">


    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

      <!-- The parameters of each page -->
      <fo:layout-master-set>
        <fo:simple-page-master master-name="PageMaster" page-height="297.00mm" page-width="210.00mm">
          <fo:region-body margin-bottom="5.00mm" margin-top="5.00mm" margin-left="5mm" margin-right="5mm"/>
        </fo:simple-page-master>
      </fo:layout-master-set>


      <fo:page-sequence master-reference="PageMaster" force-page-count="no-force">


        <fo:flow flow-name="xsl-region-body"  font-family="Impact">
          <fo:block-container>

            <xsl:for-each select="/persons/person">
              <xsl:sort select="./lastname" data-type="text" order="ascending"  /> 


              <fo:table table-layout="fixed" font-size="9.00pt" keep-together="always">

                <fo:table-column column-width="100mm" />


                <fo:table-body padding-left="10mm" table-omit-header-at-break="true">
                  <fo:table-row>
 
                   <fo:table-cell padding-top="0mm">
                      <fo:block-container >

                          <!-- Watermark -->
                          <fo:block-container height="1mm" width="1mm" overflow="visible" display-align="before">
                            <fo:block text-align="start" start-indent="40mm" >
                              <fo:external-graphic content-type="image/png" content-width="70mm" src="watermark.png"/>
                            </fo:block>
                          </fo:block-container>

                          <!-- Logo -->
                          <fo:block-container height="1mm" width="1mm" overflow="visible" display-align="before">
                            <fo:block text-align="start" start-indent="0mm" >
                              <fo:external-graphic content-type="image/png" content-width="16mm" src="logo.png"/>
                            </fo:block>
                          </fo:block-container>

                        <fo:block wrap-option="no-wrap" padding-top="3mm" >
                          <!-- affiliation -->
                          <fo:inline font-size="28" font-weight="bold" padding-left="18mm">
                         	<xsl:choose>
                              <xsl:when test="string-length(./affiliation) > 0">
                                <xsl:value-of select="./affiliation"/>
                              </xsl:when>
                              <xsl:otherwise>
                                PIRATPARTIET
                              </xsl:otherwise>
                            </xsl:choose>
                          </fo:inline>

                        </fo:block>

                        <fo:block padding-top="5mm" border-bottom="solid 2pt Black">
                        </fo:block>

                        <fo:block font-family="DejaVuSerif" white-space-collapse="false" white-space-treatment="preserve" text-align="center" padding-top="7mm">
                          <!-- nick -->
                          <fo:inline font-size="30" font-weight="bold"  wrap-option="no-wrap" >
                         	<xsl:choose>
                              <xsl:when test="string-length(./nick) > 0">
                                <xsl:value-of select="./nick"/>
                              </xsl:when>
                              <xsl:otherwise>
                                 <!-- Fall back on first name if nickname is not specified -->
                                 <xsl:value-of select="./firstname"/>
                              </xsl:otherwise>
                            </xsl:choose>
                         </fo:inline>

                        </fo:block>


                        <fo:block font-size="24" font-weight="bold"  padding-top="5mm" font-family="DejaVuSerif" white-space-collapse="false" white-space-treatment="preserve" text-align="center" >

                            <!-- first and lastname -->
                            <fo:block wrap-option="no-wrap" >
                              <xsl:value-of select="./firstname"/>
                              <xsl:text> </xsl:text>
                              <xsl:value-of select="./lastname"/>
                            </fo:block>

                        </fo:block>

                        <fo:block padding-top="1mm" border-bottom="solid 1pt Black">
                        </fo:block>

                        <!-- title -->
                        <fo:block wrap-option="no-wrap" padding-top="1mm" padding-bottom="5mm" font-family="DejaVuSerif" font-size="18" white-space-collapse="false" white-space-treatment="preserve" text-align="center" >
                         	<xsl:choose>
                              <xsl:when test="string-length(./title) > 0">
                                <xsl:value-of select="./title"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <fo:inline color="#FFF">
                                  1
                                </fo:inline>
                              </xsl:otherwise>
                            </xsl:choose>
                        </fo:block>

                      </fo:block-container>

                    </fo:table-cell>


                  </fo:table-row>

                </fo:table-body>
              </fo:table>


            </xsl:for-each>

          </fo:block-container>

        </fo:flow>

      </fo:page-sequence>


    </fo:root>
  </xsl:template>


</xsl:stylesheet>



